package top.hzy520.sms.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.hzy520.common.constants.Constants;
import top.hzy520.common.resp.APIResult;
import top.hzy520.common.rest.BaseController;
import top.hzy520.sms.service.SmsService;

import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 21:22 2018/5/28
 */
@RestController
@RequestMapping("/sms")
public class SmsController extends BaseController {
    @Autowired
    @Qualifier("smsServiceImpl")
    private SmsService smsService;
    /**
    *@Author: HouZeYu
    *@Description: 发送短信
    *@Date: 17:21 2018/6/2
    */
     @RequestMapping("/send")
    public APIResult sendVerifyCode(String mobile, HttpServletRequest request) throws UnsupportedEncodingException {
     smsService.sendSms(mobile,getIpFromRequest(request));
      return new APIResult("验证码已经发送",Constants.RESP_STATUS_OK);
    }
    /**
    *@Author: HouZeYu
    *@Description: 验证手机验证码
    *@Date: 17:21 2018/6/2
    */
    @RequestMapping("/verify")
    public boolean verifyMobileCode(String mobile,String code){
         return  smsService.verifyCode(mobile,code);
    }
}
